package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.entity.CityEntity;
import com.luck.easyfoodbatch.indexablelistview.IndexBarAdapter;

/**
 * Created by YoKeyword on 16/3/20.
 */
public class SaleAreaAdapter extends IndexBarAdapter<CityEntity> {
    private Context mContext;


    public SaleAreaAdapter(Context context) {
        mContext = context;
    }

    @Override
    protected TextView onCreateTitleViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tv_title_city, parent, false);
        return (TextView) view.findViewById(R.id.tv_title);
    }

    @Override
    protected ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sale, parent, false);
        return new CityViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(ViewHolder holder, final CityEntity cityEntity) {
        final CityViewHolder cityViewHolder = (CityViewHolder) holder;
        if (cityEntity.isChecked()) {
            cityViewHolder.iv_box.setImageResource(R.mipmap.select_sel_1x);
        } else {
            cityViewHolder.iv_box.setImageResource(R.mipmap.select_def_1x);
        }
        cityViewHolder.tvCity.setText(cityEntity.getName());
    }


    class CityViewHolder extends ViewHolder {
        TextView tvCity;
        ImageView iv_box;
        RelativeLayout relativeLayout;

        public CityViewHolder(View view) {
            super(view);
            tvCity = (TextView) view.findViewById(R.id.tv_name);
            iv_box = (ImageView) view.findViewById(R.id.iv_box);
            relativeLayout = (RelativeLayout) view.findViewById(R.id.rl_city);
        }
    }

}